package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 流程审批状态
 * @author wufeng
 * @date 2018/8/27 11:14
 */
@Getter
public enum FlowStatusEnum {

    /**
     * 无需审批
     */
    NOT_NEED_APPROVAL(0, "enum.flowStatus.memo.not_need_approval", "", "notNeedApproval"),
    /**
     * 待审批
     */
    APPROVAL_PENDING(1, "enum.flowStatus.memo.approval_pending", "#FF8E3D", "approvalPending"),
    /**
     * 审批通过
     */
    PASS(2, "enum.flowStatus.memo.pass", "#5BA307", "pass"),
    /**
     * 拒绝
     */
    REJECT(3, "enum.flowStatus.memo.reject", "#E05353", "reject"),
    /**
     * 审批中
     */
    IN_APPROVAL(4, "enum.flowStatus.memo.in_approval", "#FF8E3D", "inApproval"),
    /**
     * 回退
     */
    REFUSE(5, "enum.flowStatus.memo.refuse", "#FF8E3D", "refuse"),
    /**
     * 撤回
     */
    REVOKE(6, "enum.flowStatus.memo.revoke", "", "revoke"),
    ERROR_UNKNOWN(10, "enum.flowStatus.memo.error_unknown", "", "errorUnknown");

    private Integer type;

    private String memo;

    private String color;

    private String alias;

    FlowStatusEnum(Integer type, String memo, String color, String alias) {
        this.type = type;
        this.memo = memo;
        this.color = color;
        this.alias = alias;
    }

    public static String getMemoByType(Integer type) {
        for (FlowStatusEnum flowStatusEnum: values()){
            if(flowStatusEnum.getType().equals(type)){
                return flowStatusEnum.getMemo();
            }
        }
        return null;
    }

    public static FlowStatusEnum getFlowStatusEnumByType(Integer type) {
        for (FlowStatusEnum flowStatusEnum: values()){
            if(flowStatusEnum.getType().equals(type)){
                return flowStatusEnum;
            }
        }
        return null;
    }

    public static boolean inApproval(Integer flowStatus){
        return !(Objects.equals(NOT_NEED_APPROVAL.getType(),flowStatus) || Objects.equals(PASS.getType(),flowStatus));
    }

    /**
     * 待审批，审批中
     * @param
     * @return
     */
    public static List<Integer> inApproval(){
        return Arrays.asList(IN_APPROVAL.getType(), APPROVAL_PENDING.getType());
    }

    /**
     * 数据生效或者待生效的状态
     * 无需审批，审批通过，审批中，待审批
     * @return
     */
    public static List<Integer> normalStatus(){
        return  Arrays.asList(NOT_NEED_APPROVAL.getType(), PASS.getType(), IN_APPROVAL.getType(), APPROVAL_PENDING.getType());
    }

    /**
     * 无需审批和通过
     *
     * @return java.util.List<java.lang.Integer>
     * @author 徐俊杰
     * @date 2019/6/28 17:00
     * @since v1.0
     */
    public static List<Integer> getStatisticType() {
        return Arrays.asList(NOT_NEED_APPROVAL.getType(), PASS.getType());
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

}
